package com.jushu.storbox.actions;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.jushu.storbox.ShareDriveApplication;
import com.jushu.storbox.callback.IDownloadThumbnailCallback;
import com.jushu.storbox.constant.MessageCode;
import com.jushu.storbox.task.tqueue.DownloadThumbnailTask;

public class ThumbnailAction extends BaseAction {

	public void downloadThumbnailIcon(Context context, String ownerBy, 
			final String nodeId, final String iconPath,
	        final Handler messageHandler) {
		if(ShareDriveApplication.getInstance().getWifiController().getNetworkState()) {
			if (!checkToken(context, messageHandler)) {
				return;
			}
	        DownloadThumbnailTask task = new DownloadThumbnailTask(
	        		ShareDriveApplication.getInstance().getAuthorization(), ownerBy, nodeId, iconPath,
	        		new IDownloadThumbnailCallback() {
	        			public void onStart() { }
	        			public void onFailure(Throwable t) { }
	        			public void onProgress(int currentProgress,long currentSize, long maxSize) { }
	        			public void onSuccess(String fileId) {
	        				Message resourceMsg = messageHandler.obtainMessage();
	        				resourceMsg.what = MessageCode.REQUEST_THUMBNAIL_INLOCAL;
	        				messageHandler.sendMessage(resourceMsg);
	        			}
	        		});
	        
	        executeRunTask(task);
		}
        
    }
}
